<?php

namespace addons\Merchants;

use Yii;
use yii\db\Migration;
use common\interfaces\AddonWidget;

/**
 * 升级数据库
 *
 * Class Upgrade
 * @package addons\Merchants
 */
class Upgrade extends Migration implements AddonWidget
{
    /**
     * @var array
     */
    public $versions = [
        '1.0.0', // 默认版本
        '1.0.1',
        '1.0.2',
        '1.0.3',
    ];

    /**
    * @param $addon
    * @return mixed|void
    * @throws \yii\db\Exception
    */
    public function run($addon)
    {
        switch ($addon->version) {
            case '1.0.1' :
                $this->addColumn('{{%merchant_cate}}', 'cash_deposit', "double(10,2) unsigned NULL DEFAULT '0' COMMENT '保证金'");
                break;
            case '1.0.2' :
                $this->addColumn('{{%merchant}}', 'collect_num', "int(10) unsigned NULL DEFAULT '0' COMMENT '收藏数量'");
                $this->addColumn('{{%merchant}}', 'comment_num', "int(10) unsigned NULL DEFAULT '0' COMMENT '评价数'");
                $this->addColumn('{{%merchant}}', 'transmit_num', "int(10) unsigned NULL DEFAULT '0' COMMENT '分享数'");
                break;
            case '1.0.3' :
                $this->addColumn('{{%merchant_commission_withdraw}}', 'service_charge', "decimal(10,2) NULL DEFAULT '0.00' COMMENT '手续费率金额'");
                $this->addColumn('{{%merchant_commission_withdraw}}', 'service_charge_rate', "decimal(10,2) NULL COMMENT '手续费率'");
                $this->addColumn('{{%merchant_commission_withdraw}}', 'service_charge_single', "decimal(10,2) NULL DEFAULT '0.00' COMMENT '手续费单笔'");
                $this->addColumn('{{%merchant_commission_withdraw}}', 'service_charge_total', "decimal(10,2) NULL DEFAULT '0.00' COMMENT '总手续费'");
                break;
        }
    }
}